package com.huanong.controller.impl;
/*
 *@Author:anran
 *@Date:2020/12/7
 *@Version 1.0
 */

import com.huanong.common.grace.result.GraceJSONResult;
import com.huanong.controller.ProductControllerApi;
import com.huanong.pojo.Product;
import com.huanong.pojo.vo.ProductInsertVo;
import com.huanong.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductController implements ProductControllerApi {

    @Autowired
    private ProductService productService;

    @Override
    public GraceJSONResult queryProduct() {
        List<Product> list=productService.query();
        return GraceJSONResult.ok(list);
    }

    @Override
    public GraceJSONResult queryProductById(Integer PtId) {
        Product product=productService.queryById(PtId);
        return GraceJSONResult.ok(product);
    }

    @Override
    public GraceJSONResult queryProductByClassifyId(Integer tsId) {
        List<Product> list = productService.queryByClassifyId(tsId);
        return GraceJSONResult.ok(list);
    }

    @Override
    public GraceJSONResult addProduct(ProductInsertVo product) {
        int flag=productService.add(product);
        if (flag==1){
            return GraceJSONResult.ok("新增产品信息成功");
        }else {
            return GraceJSONResult.errorMsg("新增产品信息失败");
        }
    }

    @Override
    public GraceJSONResult deleteProduct(Integer PtId) {
        int flag=productService.delete(PtId);
        if (flag!=0){
            return GraceJSONResult.ok("删除产品信息成功");
        }else {
            return GraceJSONResult.errorMsg("删除产品信息失败");
        }
    }

    @Override
    public GraceJSONResult updateProduct(ProductInsertVo product) {
        int flag=productService.update(product);
        if (flag!=0){
            return GraceJSONResult.ok("更新产品信息成功");
        }else {
            return GraceJSONResult.errorMsg("更新产品信息失败");
        }
    }
}
